package com.yingxin.yx.framework.commons.help;

import com.yingxin.yx.framework.commons.helper.DecimalHelper;

import java.math.BigDecimal;

public class WeightHelper {

    /**
     * KG 转 吨
     * @param weight
     * @return
     */
    public static BigDecimal convertToTon(BigDecimal weight) {
        if (weight == null) {
            return BigDecimal.ZERO;
        }
        return DecimalHelper.divide(weight, BigDecimal.valueOf(1000), 3);
    }

    public static BigDecimal convertToKg(BigDecimal weight) {
        if (weight == null) {
            return BigDecimal.ZERO;
        }
        return DecimalHelper.multiply(weight, BigDecimal.valueOf(1000));
    }


    public static BigDecimal convertToTon(String weight) {
        if (weight == null) {
            return BigDecimal.ZERO;
        }
        return DecimalHelper.divide(new BigDecimal(weight), BigDecimal.valueOf(1000), 3);
    }

    public static BigDecimal convertToKg(String weight) {
        if (weight == null) {
            return BigDecimal.ZERO;
        }
        return DecimalHelper.multiply(new BigDecimal(weight), BigDecimal.valueOf(1000));
    }

}
